﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Mvc;

namespace KingRoad.EPM.Web.Areas.CompletionMaterials.CompletionMaterialsFramework.Mvc
{
    /// <summary>
    /// ButtonExtensions
    /// HTML标签按钮扩展类。
    /// 
    /// 修改纪录
    /// 
    /// 版本：1.0
    /// 
    /// <author>
    ///		<name>WS</name>
    ///		<date>2011.09.22</date>
    /// </author> 
    /// </summary>
    public static class ButtonExtensions
    {
        /// <summary>
        /// 根据权限编码判断按钮是否显隐 WS 11.9.22
        /// </summary>
        /// <param name="?"></param>
        /// <param name="code"></param>
        /// <param name="cssClass"></param>
        /// <param name="href"></param>
        /// <param name="rel"></param>
        /// <param name="target"></param>
        /// <param name="title"></param>
        /// <param name="mask"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static MvcHtmlString PermissionButton(this HtmlHelper helper, 
            string code, 
            string id, 
            string cssClass, 
            string href, 
            string rel, 
            string target, 
            string title, 
            string mask, 
            string width, 
            string height, 
            string name, string iclass = "")
        {
            string returnString = String.Empty;

            //if (new UserService().IsIsAuthorized(code))
            //{
            returnString = String.Format("<a class=\"{0}\" id=\"{9}\" href=\"{1}\" rel=\"{2}\" target=\"{3}\" title=\"{4}\" mask=\"{5}\" width=\"{6}\" height=\"{7}\"><span></span><em>{8}</em></a>", cssClass, href, rel, target, title, mask, width, height, name, id);
            //}
            return new MvcHtmlString(returnString);
        }
        /// <summary>
        /// 根据权限编码判断按钮是否显隐 WS 11.9.22
        /// </summary>
        /// <param name="?"></param>
        /// <param name="code"></param>
        /// <param name="cssClass"></param>
        /// <param name="href"></param>
        /// <param name="rel"></param>
        /// <param name="target"></param>
        /// <param name="title"></param>
        /// <param name="mask"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static MvcHtmlString PermissionButton(this HtmlHelper helper, 
            string code, 
            string id, 
            string cssClass, 
            string href, 
            string rel, 
            string target, 
            string title, 
            string mask, 
            string name, 
            string iclass = "")
        {
            string returnString = String.Empty;

            //if (new UserService().IsIsAuthorized(code))
            //{
                if (string.IsNullOrWhiteSpace(iclass))
                {
                    returnString = String.Format("<a class=\"{0}\" id=\"{7}\" href=\"{1}\" rel=\"{2}\" target=\"{3}\" title=\"{4}\" mask=\"{5}\"><span></span><em>{6}</em></a>", cssClass, href, rel, target, title, mask, name, id);
                }
                else
                {
                    returnString = String.Format("<a class=\"{0}\" id=\"{7}\" href=\"{1}\" rel=\"{2}\" target=\"{3}\" title=\"{4}\" mask=\"{5}\"><i class=\"{8}\"></i>{6}</a>", cssClass, href, rel, target, title, mask, name, id, iclass);
                }
            //}

            return new MvcHtmlString(returnString);
        }
        /// <summary>
        /// 根据权限编码判断按钮是否显隐 ThinkWang 2012-12-24
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="code">权限编码</param>
        /// <param name="id"></param>
        /// <param name="href"></param>
        /// <param name="text">文字</param>
        /// <param name="htmlAttributes">html属性</param>
        /// <returns></returns>
        public static MvcHtmlString PermissionButton(this HtmlHelper helper, string code, string id, string href, string text, IDictionary<string, object> htmlAttributes, string iclass = "")
        {
            StringBuilder sb = new StringBuilder();
            //if (new UserService().IsIsAuthorized(code))
            //{
                sb.AppendFormat("<a id=\"{0}\" href=\"{1}\"", id, href);
                foreach (var item in htmlAttributes)
                {
                    sb.AppendFormat(" {0}=\"{1}\"", item.Key, item.Value);
                }
                if (string.IsNullOrWhiteSpace(iclass))
                    sb.AppendFormat(" ><span title=\"{0}\" ></span><em>{0}</em></a>", text);
                else
                    sb.AppendFormat(" ><i class=\"{1}\"></i>{0}</a>", text, iclass);
            //}
            return new MvcHtmlString(sb.ToString());
        }
    }
}
